import MyLayout from '../shared/MyLayout';
import Home from '@/pages/home/Home';
import My from '@/pages/my/My';
import Login from '@/pages/login/Login';
import NotFound from '@/pages/error/NotFound';
import Good from '@/pages/good/Good';
import { IndexRouteObject, NonIndexRouteObject } from 'react-router-dom';
import Chart from '@/pages/chart/Chart';
import Supplier from '@/supplier/Supplier';
import Order from '@/pages/order/Order';
import History from '@/pages/history/History';
import Collection from '@/pages/collection/Collection';
import SearchPage from '@/pages/search/SearchPage';
import Comments from '@/pages/comment/Comments';
import MyComment from '@/pages/comment/pendding/MyComment';
import CommentAdd from '@/pages/comment/add/CommentAdd';
import ErrorBoundary from './errorBoundary';

interface CustomIndexRouteObject extends IndexRouteObject {
  title?: string;
  hideNavbar?: boolean;
}

interface CustomNonIndexRouteObject extends NonIndexRouteObject {
  title?: string;
  hideNavbar?: boolean;
  children?: CustomRouteObject[];
}

type CustomRouteObject = CustomIndexRouteObject | CustomNonIndexRouteObject;

const routes: CustomRouteObject[] = [
  {
    path: '/',
    Component: MyLayout,
    title: '',
    errorElement: <ErrorBoundary />,
    children: [
      {
        index: true,
        Component: Home,
        title: '首页',
      },
      {
        path: 'chart',
        title: '购物车',
        Component: Chart,
      },
      {
        path: 'my',
        title: '我的',
        Component: My,
      },
      {
        path: 'good/:id',
        title: '商品详情',
        Component: Good,
      },
      {
        path: 'supplier/:id',
        title: '供应商',
        Component: Supplier,
      },
      { path: 'order', title: '订单', Component: Order },
      { path: 'history', title: '浏览历史', Component: History },
      { path: 'collection', title: '收藏', Component: Collection },
      { path: 'search', title: '搜索', Component: SearchPage, hideNavbar: true },
      {
        path: 'comment',
        title: '商品评论',
        Component: Comments,
      },
      {
        path: 'myComment',
        title: '我的评论',
        Component: MyComment,
      },
      {
        path: 'addComment',
        title: '发布评论',
        Component: CommentAdd,
      },
    ],
  },
  { path: '/login', Component: Login },
  { path: '*', Component: NotFound },
];

export default routes;
